package service

import (
	"github.com/gin-gonic/gin"
	"monment/basic/config"
	"monment/handler/model"
	"monment/handler/request"
	"net/http"
)

func GetPostList(c *gin.Context) {
	var form request.GetPostList
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "参数错误",
		})
		return
	}
	var post model.Post
	list, err := post.GetPostList(config.DB, form.Page, form.Size)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "获取动态列表失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "获取动态列表成功",
		"data": gin.H{
			"postList": list,
		},
	})
	return
}
